package com.learn.twoday;

import org.apache.log4j.Logger;

import java.util.concurrent.TimeUnit;

/**
 * @author ln
 * @Description: ${todo}
 * @date 2020/12/9
 */
public class InterruptTest {

    private static final Logger logger=Logger.getLogger(InterruptTest.class);

    public static void main(String[] args) {
        Thread t1=new Thread(()->{
            while (true){
                boolean interrupted = Thread.currentThread().isInterrupted();
                if(interrupted){
                    logger.debug("被打断了，退出循环");
                    break;
                }
            }
        },"t1");
        t1.start();

        try {
            TimeUnit.SECONDS.sleep(1);
            logger.debug("interrupt");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
